package com.coinworld.exception;

import com.coinworld.object.HttpJsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @description 全局异常捕获
 * @author:
 * @create: 2019-08-28 15:29
 **/
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public HttpJsonResult defaultExceptionHandler(Exception e) {
        e.printStackTrace();
        if (e instanceof BusinessException){
            BusinessException be = (BusinessException) e;
            return HttpJsonResult.fail(be.getMessage());
        }
        log.error("=============>GlobalExceptionHandler intercept Exception error : {}", e.getLocalizedMessage(), e);
        return HttpJsonResult.fail("操作失败！");
    }



}
